package com.xiao.xin.core.Config;

import com.xiao.xin.core.Interceptor.UserInterceptor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.Collections;

/***
 * 配置拦截器
 */
@Slf4j
@RequiredArgsConstructor
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private static final ArrayList<String> excludePathPatterns = new ArrayList<>();

    static {
        Collections.addAll(excludePathPatterns,
                "/api/1.0/user/**","/error","/ws/**"
        );
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("拦截器开启成功");
        registry.addInterceptor(new UserInterceptor()).addPathPatterns("/**").excludePathPatterns(excludePathPatterns);
    }
}
